package com.competition.jingdong;

import java.io.BufferedReader;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
//订单
//,订单号,SKU编码,数量
public class OrderCsvProcess{
    public void processing(Path path, String charset, List list) {
        try {
            int order_count =0;
            BufferedReader br = Files.newBufferedReader(path, Charset.forName(charset));
            String s = br.readLine();//处理标题栏
            s=br.readLine();
            Integer present_order = null;
            HashMap<Integer,Integer> skuNo_count = new HashMap<>();
            Integer orderNo=null;
            while(s!=null)
            {
                String[] sArray = s.split(",");
                present_order = Integer.valueOf(sArray[1]);
                if(present_order.equals(orderNo)) {
                    skuNo_count.put(Integer.valueOf(sArray[2]), Integer.valueOf(sArray[3]));
                }
                else
                {
                    if(orderNo!=null)
                    {
                        Order order = new Order(orderNo,skuNo_count);
                        list.add(order);
                        order_count++;
                        skuNo_count = new HashMap<>();
                    }
                    orderNo=present_order;
                    skuNo_count.put(Integer.valueOf(sArray[2]), Integer.valueOf(sArray[3]));
                }
                s=br.readLine();
            }
            if(skuNo_count!=null)
            {
                Order order = new Order(orderNo,skuNo_count);
                list.add(order);
                order_count++;
            }
            System.out.println("order_count="+order_count);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
